// pages/Main/mainIndex/mainIndex.js
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')
let asign = 0;
let bbb = [];
const conf = {

  /** 
   * 页面的初始数据
   */
  data: {
    content: [],
    content2: [],
    orgid: "",
    userid: "",
    ti: [],
    ryid: "",
    num: 1,
    scrollHeight: 0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    this.setData({
      ryid: options.id,
      orgid: c.orgid,
      userid: c.userid,
      parid: options.paperid,
      examid: options.id,
      scrollHeight: scrollHeight,
    });
    this.list();
    // console.log(this.data.ryid)
  },
  getdata: function (alength, data, res) {
    if (asign == alength) {
      //console.log(bbb)
      asign=0;
    } else {
      //6.6.1
      let params = {
        "orgid": data.orgid, "userid": data.userid, "searchField": "peopleid,examid", "searchValue": "" + res[asign].id + "," + this.data.ryid + ""
      }
      businessLogic.QueryPapersSubmitted(params, (resa) => {
        //var res = res.infos;
        console.log(res)
        bbb.push(resa);
        for (var k = 0; k < res.length; k++) {
          res[k].aaaaa = bbb[k];
        }
        this.setData({
          content: res
        });
       // common.hideLoading();
        console.log("cont", this.data.content)
        asign += 1;
        this.getdata(alength, data, res);
      })

    }

  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      this.list();
    } else {
      common.showToast("到底了", "loading");
    }
  },
  //6.2.1
  list: function () {
   // common.showLoading("加载中", "loading");
    var aaa = [];
    // 第二步 传参
    let params = {
      "page": this.data.num, "num": 15, "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "departmentid", "searchValue": "92ef7278-0ebc-41e4-beaf-13dab650b0ed,077ba48e-76f8-4afd-8a84-67b4f2ed3762"
    }
    //第三步 调用接口
    businessLogic.QueryStudentlist(params, (res) => {
      console.log("6.2.1", res)
      var page = res.page
      var res = res.infos;
      //第五步 把获取的值，传入data
      var bbb = this.data.content
      for (let a = 0; a < res.length; a++) {
        bbb.push(res[a]);
      }
      this.setData({
        content: bbb,
        lenpage: page.pages
      });
      let a = 0;
      for (let a = 0; a < this.data.content.length; a++) {
        aaa[aaa.length] = this.data.content[a];
        if (a == (this.data.content.length - 1)) {
          this.getdata(aaa.length, this.data, res)
        }
      };
    });

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    asign = 0;
     bbb = [];
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  answeron: function (event) {
    if (event.currentTarget.dataset.pigai == 1) {
      wx.navigateTo({
        /*   url: "../answeron/answeron?title='班级测试统计'&&remarktype=1&&examtype=1&&examid="+this.data.examid+"&&parid=" +this.data.parid */
        url: "../classTestvie/classTestvie?examid=" + this.data.examid + "&&parid=" + this.data.parid + "&&name=" + event.currentTarget.dataset.name + "&&jlid=" + event.currentTarget.dataset.jlid
      });
    }

  },
};
Page(conf);